package hotel.quartz.oversea.job.callback;

import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.utils.GsonUtils;
import hotel.base.oversea.utils.Result;
import hotel.quartz.oversea.config.service.RedisService;
import hotel.quartz.oversea.job.base.BaseJob;
import hotel.quartz.oversea.util.JobRestTemplateUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;


/**
 * 十分钟执行一次，重新查询标准价
 */
@Slf4j
public class MtCbGoodsPriceLibraryThisWeekJob implements BaseJob {
    private String timestamp = "Mcgplj"+String.valueOf(System.currentTimeMillis());

    @Autowired
    RedisService redisService;

    @Autowired
    RestTemplate restTemplate;


    /**
     *   十分钟执行一次，重新查询标准价
     *   数据来源：主动和异步判断中，加入队列，让定时器执行重新查询且为本周今天的昨天的标准价
     *
     * @param jobExecutionContext
     */
    @Override
    @SneakyThrows
    public void execute(JobExecutionContext jobExecutionContext) {
        String hour = DateUtil.getCurrTimeYmd("HH");
        log.info("Mt Cb Goods Price Library This Week Job 开始  重新查询标准价,hour={}",hour);
        if(!hour.equals("01") && !hour.equals("02")){

            //调用美团方法
            Result result = JobRestTemplateUtils.post(CommonUrlConstants.MEITUAN_HOST+"/mtHotelGoods/resetWeekLibraryPriceHotels",null,restTemplate);
            if(result.getCode()== CommonConstants.SUCCESS){
                log.info("Mt Cb Goods Price Library Job 重新查询标准价返回={}", GsonUtils.GsonString(result));
            }else{
                log.error("Mt Cb Goods Price Library Job 异常 重新查询标准价失败={}", GsonUtils.GsonString(result));
            }

        }
        log.info("Mt Cb Goods Price Library This Week Job 结束 重新查询标准价");
    }


}
